//
//  OSMeViewController.m
//  百思不得姐
//
//  Created by gl on 16/2/19.
//  Copyright © 2016年 CoderC. All rights reserved.
//

#import "OSMeViewController.h"
#import "OSMeCell.h"
#import "OSMeFooterView.h"
#import "OSMeFooterCell.h"
#import "OSLoginRegisterViewController.h"
@interface OSMeViewController() <UITableViewDataSource, UITableViewDelegate>

@end

@implementation OSMeViewController
-(void)viewDidLoad{
    [super viewDidLoad];
    
    [self setupTableView];
 
    
    
    [self setupNav];
}

static NSString  * OSMeId = @"me";

-(void)setupTableView{
    
    // 设置背景色
    self.tableView.backgroundColor = OSGlobalBg;
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[OSMeCell class] forCellReuseIdentifier:OSMeId];
    
    // 调整header和footer
    self.tableView.sectionHeaderHeight = 0;
    self.tableView.sectionFooterHeight = OSTopicCellMargin;
    
    // 调整inset
    self.tableView.contentInset = UIEdgeInsetsMake(OSTopicCellMargin - 35, 0, 100, 0);

    
    

    // 设置footerView
    self.tableView.tableFooterView = [[OSMeFooterView alloc] init];
    

}
-(void)setupNav{
    self.navigationItem.title = @"我的";
    
    // 设置导航栏右边的按钮
    UIBarButtonItem *settingItem = [UIBarButtonItem itemWithImageName:@"mine-setting-icon" highImageName:@"mine-setting-icon-click" target:self action:@selector(settingClick)];
    UIBarButtonItem *moonItem = [UIBarButtonItem itemWithImageName:@"mine-moon-icon" highImageName:@"mine-moon-icon-click" target:self action:@selector(moonClick)];
    self.navigationItem.rightBarButtonItems = @[settingItem, moonItem];
    
    
    self.view.backgroundColor = OSGlobalBg;
}
#pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 3) {
        OSMeFooterCell *footerCell = [tableView dequeueReusableCellWithIdentifier:@"footerCell"];
        if (footerCell == nil) {
            footerCell = [[OSMeFooterCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"footerCell"];
        }
        
        
        return footerCell;
    }else{
    
    
    OSMeCell *cell = [tableView dequeueReusableCellWithIdentifier:OSMeId];
    
    if (indexPath.section == 0) {
        cell.imageView.image = [UIImage imageNamed:@"mine_icon_nearby"];
        cell.textLabel.text = @"登录/注册";
    } else if (indexPath.section == 1) {
        cell.textLabel.text = @"离线下载";
    }
    
    return cell;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        
        
        OSLoginRegisterViewController *loginVc = [[OSLoginRegisterViewController alloc]init];
        
        [self presentViewController:loginVc animated:YES completion:nil];
        
        
    }
}
-(void)settingClick{
    
}
-(void)moonClick{
    
}
@end
